/**
 * 获取用户信息
 */
getUser();

function getUser() {
	$.ajax({
		type: "POST",
		url: ip + "platform/user/reacquire.m",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(data) {
			if(data.statusCode == 0) {
				$("#phone").val((data.result.mobile).replace("+86|", ""));
			} else if(data.statusCode == 1000) {
				loginError();
			} else {
				$.toptip(data.resultDesc, 'error');
			}
		}
	});
}
/**
 * 获取短信验证码
 */
var countdown = 300;

function setInviteCode(val) {
	if(/^1(3|4|5|6|7|8|9)\d{9}$/.test($("#phone").val().trim())) {
		number = "+86|" + $("#phone").val().trim();
	} else {
		number = $("#phone").val().trim();
	}
	var getInviteCodeReqbody = {
		"type": 0,
		"mobile": number
	};
	$.ajax({
		type: "POST",
		url: ip + "platform/user/serverGetValidateCode.m",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		data: getInviteCodeReqbody,
		success: function(data) {
			if(data.statusCode == 0) {
				$.toptip("短信验证码已发送到手机！", 'success');
				getInviteCode(val);
			} else {
				$.toptip(data.resultDesc, 'error');
			}
		}
	});
}

function getInviteCode(val) {
	if(countdown == 0) {
		val.removeAttribute("disabled");
		val.value = "验证码";
		countdown = 300;
	} else {
		val.setAttribute("disabled", true);
		val.value = countdown + "秒";
		countdown--;
	}
	setTimeout(function() {
		getInviteCode(val)
	}, 1000);
}
/**
 * 设置支付密码的页面逻辑
 */
var first = true;

function paymentpassword2() {
	//$(".weui-btn").attr("disabled", false);
	if($("#validateCode").val().trim() == '') {
		$.toast("短信验证码不能为空!", "text");
		return false;
	}
	if($("#newpassword").val().trim() == '') {
		$.toast("支付密码不能为空!", "text");
		return false;
	}
	if($("#repassword").val().trim() == '') {
		$.toast("确认支付密码不能为空!", "text");
		return false;
	}
	if($("#newpassword").val().trim() != $("#repassword").val().trim()) {
		$.toast("两次密码不一致，请检查!", "text");
		return false;
	}
	if(/^1(3|4|5|6|7|8|9)\d{9}$/.test($("#phone").val().trim())) {
		number = "+86|" + $("#phone").val().trim();
	} else {
		number = $("#phone").val().trim();
	}
	var registerReqbody = {
		"type": 0,
		"number": number,
		"newpassword": $("#newpassword").val().trim(),
		"repassword": $("#repassword").val().trim(),
		"validateCode": $("#validateCode").val().trim()
	};
	if(first) {
		first = false;
		$.ajax({
			type: "POST",
			url: ip + "platform/user/findPayPwd.m",
			xhrFields: {
				withCredentials: true
			},
			crossDomain: true,
			data: registerReqbody,
			success: function(data) {
				if(data.statusCode == 0) {
					//$(".weui-btn").attr("disabled", true);
					$.toptip("修改绑定手机成功！", 'success');
					setTimeout(function(){
				       mui.openWindow({
							createNew:true,// 打开并且刷新：true刷新，false不刷新
							show:{
								autoShow:true,
								aniShow:'fade-in',
							},
							url: 'securitySetting.html',
							id: 'securitySetting'
						});
					},1000);
				} else if(data.statusCode == 1000) {
					loginError();
				} else {
					$.toptip(data.resultDesc, 'error');
					first = true;
				}
			}
		});
	}
}